<?php
include 'islogin.php';
include '../config.php';
	
if( isset($_GET['flag']))
{
	if($_GET['flag']=="update")
	{
		$sql = "select id,name,city,address,path,remark,type,contact_name,shop_address,phone from dealer where id=".$_GET['id'];
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
	}
}
if(isset($_POST['flag']))
{
	if($_POST['flag']=="update")
	{
		$sql = "update dealer set `type`='".$_POST['type']."', `name`='".$_POST['name']."', city='".$_POST['city']."', address ='".$_POST['address']."',path ='".$_POST['path']."' ,remark = '".$_POST['remark']."',shop_address='".$_POST['shop_address']."', contact_name='".$_POST['contact_name']."', phone='".$_POST['phone']."' where id =".$_POST['id'];
		mysql_query($sql);
		echo "<script>window.location.href='dealer_list.php'</script>";
	}
	if($_POST['flag']=="add")
	{
		$sql = "insert into dealer(`type`,name,city,address,path,remark,flag,shop_address,contact_name,phone) values('".$_POST['type']."','".$_POST['name']."','".$_POST['city']."','".$_POST['address']."', '".$_POST['path']."','".$_POST['remark']."','".$_POST['shop_address']."','".$_POST['contact_name']."','".$_POST['phone']."',1)";
		
		mysql_query($sql);
		echo "<script>window.location.href='dealer_list.php'</script>";
	}
	
}
?>
<script src="../js/jquery-1.7.1.js"></script>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css"/>
<link href="js/upload/uploadify.css" rel="stylesheet" type="text/css" />
<script src="js/upload/swfobject.js"></script>
<script src="js/upload/jquery.uploadify.v2.1.4.min.js"></script>
<script>
	$(document).ready(function(){ 
           $("#type").change(function(){               if($(this).val() == 1){                   $('#shop_address').parent().parent().hide();        	       $('#contact_name').parent().parent().show();        	       $('#phone').parent().parent().show();        	       $('#address').show().prev().show();               }else if($(this).val() == 2){        	       $('#shop_address').parent().parent().show();        	       $('#contact_name').parent().parent().hide();        	       $('#phone').parent().parent().hide();        	       $('#address').hide().prev().hide();               }           });           $('#type').trigger('change');
		   $('#img_upload').uploadify({
			   'uploader':'js/upload/uploadify.swf',
			   'cancelImg':'js/upload/cancel.png',
			   'fileExt':'*.png',
			   'script':'uploadify.php',
			   'auto':true,
			   'folder':'upload',
			   'buttonImg':'/admin/images/Browse.png',
			   'width':70,
			   'height':25,
			   'wmode':'transparent',
			   'onComplete':function(event,queueId,fileObj,response,data){
				   	 
				     $("#path").val(response);
				   }
	     });
		});
</script>
<div style="border:0px solid red;"> 

    	<div id="top"><div>经销网点</div></div>
    	
	    <div id="middle">
	     <div class="layout">
		  	<div class="title">网点管理</div>
		       <div class="content">
			       <form action="dealer_add.php" method="post">
			         <input type="hidden" name="flag" value="<?php if(isset($row)){echo "update";}else{echo "add";}?>" />
			         <input type="hidden" name="id" value="<?php if(isset($row)){echo $row['id'];}?>" />
			          <table  cellspacing="0" cellpadding="0">  			          	<tr>			          		<td class="title_some_td" style="width:100px;">类型:</td>			          		<td>			          		   <select name="type" id="type">			          		      <option <?php if(isset($row) && $row['type'] ==1) echo "selected='selected'";?> value="1">实体店</option>			          		      <option <?php if(isset($row) && $row['type'] ==2) echo "selected='selected'";?> value="2">淘宝店</option>			          		   </select>			          		</td>			          	</tr>
			          	<tr>
			          		<td class="title_some_td" style="width:100px;">名称:</td>
			          		<td><input name="name" id="name" value="<?php if(isset($row)){echo $row['name'];}?>"  /></td>
			          	</tr>			          	<tr>			          		<td class="title_some_td" style="width:100px;">店铺地址:</td>			          		<td><input name="shop_address" id="shop_address" value="<?php if(isset($row) && $row['type'] == 1){echo $row['shop_address'];}?>"  /></td>			          	</tr>                        <tr>			          		<td class="title_some_td" style="width:100px;">联系人:</td>			          		<td><input id="contact_name" name="contact_name" value="<?php if(isset($row) && $row['type'] == 1){echo $row['contact_name'];}?>"  /></td>			          	</tr>                        <tr>			          		<td class="title_some_td" style="width:100px;">电话:</td>			          		<td><input id="phone" name="phone" value="<?php if(isset($row) && $row['type'] == 1){echo $row['phone'];}?>"  /></td>			          	</tr>			          	
			          	<tr>
			          		<td class="title_some_td" style="width:100px;">地区:</td>
			          		<td>
			          			<input name="city" id="city" value="<?php if(isset($row)){echo $row['city'];}?>"/><span style="font-size:12px;">省/市</span>
			          			<input name="address" id="address" value="<?php if(isset($row)){echo $row['address'];}?>"  />
			          		</td>
			          	</tr>
			          	
			          	
			          	 <tr>
			          		<td class="title_some_td" style="width:100px;">授权商品:</td>
			          		<td><textarea style="" rows="5" cols="30" name="remark"><?php if(isset($row)){echo $row['remark'];}?></textarea></td>
			          	</tr>
			          	<tr>
			          		<td></td>
			          		<td><input type="submit" value="保存" /></td>
			          	</tr>
			          </table>
			      </form>    
		      </div>
		  </div>
	    </div>
	    
	    <div id="bottom"></div>		
</div>	    